package com.myway.dto.flight;

import com.myway.dto.pricing.DTOFare;
import com.myway.dto.pricing.DTOProductOffer;
import com.myway.dto.rule.DTORuleRule;
import org.apache.commons.collections.CollectionUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 类名称：DTOCabin 
 * 类描述：TODO 舱位DTO
 * 创建时间：2015年10月26日 下午6:10:32 
 * @author Jiang.Yida
 * @version V1.0
 */
public class DTOCabin implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8995529488758123L;
	/**
	 * 舱位代码
	 */
	private String cabinCode;
	/**
	 * 可销售数
	 */
	private int inventory;
	/**
	 * 成人价
	 */
	private DTOFare adultFare;
	/** 
	 * 儿童价
	 */
	private DTOFare childFare;
	/**
	 * 婴儿价 
	 */
	private DTOFare infantFare;	
	/**
	 * 此舱位可销售的产品，由规则引擎添加。
	 */
	private List<DTOProductOffer> productOffers = new ArrayList<DTOProductOffer>();
	
	/**
	 * ruleinfo: 规则信息 
	 */
	private DTORuleRule ruleinfo;
	
	/**
	 * 预定状态
	 */
	private String status;

	/**
	 * 舱位代码注释
	 */
	private String cabinCodeDesc;
	
	/**
	 * 舱位注释
	 */
	private String remark;
	
	/**
	 * 国际票成人价
	 */
//	private DTOIntlFare adultFareIntl;
//	/** 
//	 * 国际票儿童价
//	 */
//	private DTOIntlFare childFareIntl;
//	/**
//	 * 国际票婴儿价 
//	 */
//	private DTOIntlFare infantFareIntl;	
	/**
	 * 团购人数
	 */
	private int groupCount;
	
	/**
	 * 参考舱位
	 */
	private String referenceCabin;
	
	/**
	 * 推荐的
	 */
	private boolean recommended=false;
	
	
	public DTOCabin(){
	}

	/**
	 * @return the cabinCode
	 */
	public String getCabinCode() {
		return this.cabinCode;
	}

	/**
	 * @param cabinCode the cabinCode to set
	 */
	public void setCabinCode(String cabinCode) {
		this.cabinCode = cabinCode;
	}

	/**
	 * @return the inventory
	 */
	public int getInventory() {
		return this.inventory;
	}

	/**
	 * @param inventory the inventory to set
	 */
	public void setInventory(int inventory) {
		this.inventory = inventory;
	}

	/**
	 * 
	 * @return
	 */
	public DTOProductOffer getFinalProductOffer() {
		Collections.sort(productOffers);
		if (CollectionUtils.isNotEmpty(productOffers)) {
			return productOffers.get(0);
		}
		return null;
	}

	/**
	 * @return the status
	 */
	public String getStatus() {
		return this.status;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(String status) {
		this.status = status;
	}
	
	public String getCabinCodeDesc() {
		return cabinCodeDesc;
	}

	public void setCabinCodeDesc(String cabinCodeDesc) {
		this.cabinCodeDesc = cabinCodeDesc;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public List<DTOProductOffer> getProductOffers() {
		if (productOffers != null) {
		}
		return productOffers;
	}

	public void addProduct(String productCode) {
		if (!hasProduct(productCode)) {
			DTOProductOffer product = new DTOProductOffer();
			product.setCode(productCode);
			productOffers.add(product);
		}
	}
	
	public void removeProduct(String productCode) {
		DTOProductOffer po = getProduct(productCode);
		productOffers.remove(po);
	}
	
	public DTOProductOffer getProduct(String productCode) {
		DTOProductOffer product = null;
		
		if (productOffers == null) {
			productOffers = new ArrayList<DTOProductOffer>();
		}
		
		for (DTOProductOffer p : productOffers) {
			if (p.getCode().equals(productCode)) {
				product = p;
				break;
			}
		}
		return product;
	}

	public boolean hasProduct(String productCode) {
		return (getProduct(productCode) != null);
	}

	public DTOFare getAdultFare() {
		return adultFare;
	}
//
	public void setAdultFare(DTOFare adultFare) {
		this.adultFare = adultFare;
	}

	public DTOFare getChildFare() {
		return childFare;
	}

	public void setChildFare(DTOFare childFare) {
		this.childFare = childFare;
	}

	public DTOFare getInfantFare() {
		return infantFare;
	}

	public void setInfantFare(DTOFare infantFare) {
		this.infantFare = infantFare;
	}
	
	public void offerAdultFare(double fare) {
		if (adultFare == null) {
			adultFare = new DTOFare();
		}
		adultFare.setFarePrice(fare);
	}
	
	public void offerChildFare(double fare) {
		if (childFare == null) {
			childFare = new DTOFare();
		}
		childFare.setFarePrice(fare);
	}
	
	public void offerInfantFare(double fare) {
		if (infantFare == null) {
			infantFare = new DTOFare();
		}
		infantFare.setFarePrice(fare);
	}

//	public DTOIntlFare getAdultFareIntl() {
//		return adultFareIntl;
//	}
//
//	public void setAdultFareIntl(DTOIntlFare adultFareIntl) {
//		this.adultFareIntl = adultFareIntl;
//	}
//
//	public DTOIntlFare getChildFareIntl() {
//		return childFareIntl;
//	}
//
//	public void setChildFareIntl(DTOIntlFare childFareIntl) {
//		this.childFareIntl = childFareIntl;
//	}
//
//	public DTOIntlFare getInfantFareIntl() {
//		return infantFareIntl;
//	}
//
//	public void setInfantFareIntl(DTOIntlFare infantFareIntl) {
//		this.infantFareIntl = infantFareIntl;
//	}
//	
//	public void offerAdultFare(double fare, Currency unit){
//		if(adultFareIntl == null){
//			adultFareIntl = new DTOIntlFare();
//		}
//		
//		adultFareIntl.setFarePrice(new DTOPriceUnit(fare,unit));
//	}
//	
//	public void offerChildFare(double fare, Currency unit){
//		if(childFareIntl == null){
//			childFareIntl = new DTOIntlFare();
//		}
//		childFareIntl.setFarePrice(new DTOPriceUnit(fare,unit));
//	}
//	
//	public void offerInfantFare(double fare, Currency unit){
//		if(infantFareIntl == null){
//			infantFareIntl = new DTOIntlFare();
//		}
//		infantFareIntl.setFarePrice(new DTOPriceUnit(fare,unit));
//	}
	
	/**
	 * 添加外航机票产品
	 * @param productCode
	 * @param adultFare
	 */
	public void addOutProduct(String productCode,DTOFare adultFare,String desc) {
		if (!hasProduct(productCode)) {
			DTOProductOffer product = new DTOProductOffer();
			product.setCode(productCode);
			product.setName("明折明扣");
			product.setAdultFare(adultFare);
			product.setRecommended(false);
			product.setDescription("");
			productOffers.add(product);
		}
	}

	public int getGroupCount() {
		return groupCount;
	}

	public void setGroupCount(int groupCount) {
		this.groupCount = groupCount;
	}

	public String getReferenceCabin() {
		return referenceCabin;
	}

	public void setReferenceCabin(String referenceCabin) {
		this.referenceCabin = referenceCabin;
	}
	
	public DTORuleRule getRuleinfo() {
		return ruleinfo;
	}

	public void setRuleinfo(DTORuleRule ruleinfo) {
		this.ruleinfo = ruleinfo;
	}

	public boolean isRecommended() {
		return recommended;
	}

	public void setRecommended(boolean recommended) {
		this.recommended = recommended;
	}

}